package models;

import models.constants.AvailableStatus;

import javax.persistence.*;
import java.util.List;

/**
 * Created by liming on 16/7/12.
 */
@Entity
@Table(name = "admin_supplier")
public class AdminSupplier extends BaseModel {
    /**
     * 供应商代码
     */
    @Column(name = "code")
    public String code;

    /**
     * 供应商名称
     */
    @Column(name = "name")
    public String name;

    /**
     * 拼音简写
     */
    @Column(name = "pingyin")
    public String pinyin;

    /**
     * 联系电话
     */
    @Column(name = "phone")
    public String phone;

    /**
     * 税号
     */
    @Column(name = "tax_account")
    public String taxAccount;

    /**
     * 银行帐号
     */
    @Column(name = "bank_account")
    public String bankAccount;

    /**
     * 地址
     */
    @Column(name = "address")
    public String address;

    /**
     * 备注
     */
    @Column(name = "remark")
    public String remark;

    /**
     * 使用状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "available_status")
    public AvailableStatus availableStatus;

    /**
     * 根据ID删除供应商
     * @param id
     */
    public static void deleteById(long id){
        AdminSupplier.delete("id = ?",id);
    }

    /**
     * 获取供应商列表
     */

    public static List<AdminSupplier> loadAllSupplier(){
        return AdminSupplier.find("availableStatus=?",AvailableStatus.AVAILABLE).fetch();
    }


}
